<template>
	<view class="">
		<search placeholder="输入供应商名称搜索" @input="inputChange"></search>
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" :top="'100rpx'" @up="upCallback">
		  <uni-list>
			  <view class="item" style="padding-top: 20rpx;" @click="clickListItem(item)" v-for="(item,index) in listdata" :key="item.purchaseSupplierId">
			  	<title-content title="供应商名称:" :content=" item.supplierName"></title-content>
			  	<title-content title="联系人:" :content="item.contacts"></title-content>
			  	<title-content title="电话:" :content="item.phone"></title-content>
			  	<title-content title="详细地址:" :content="item.addrDetail"></title-content>
			  </view>
		  </uni-list>
		</mescroll-uni>
	</view>
</template>

<script>
	import titleContent from 'components/global/title-content.vue'
	import search from '../../components/search.vue';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		components: {
			titleContent,
			search
		},
		
	    data() {
			return {
				page: 1,
				listdata: [],
				searchWord: ""
			}
		},
		
		methods: {
			
			
			//获取数据
			getData() {
				this.$u.api.getPurchaseSupplierList({
						parameters: this.searchWord,
						pageNo: this.page
					}).then(
						res => {
							if (this.page == 1) {

                this.listdata = [];
              }
              this.listdata = this.listdata.concat(res);
              this.mescroll.endSuccess(res.length);
            }
					)
					.catch(() => {
						this.mescroll.endErr();
					})
			},
			
			//上拉加载回调
			upCallback(page) {
				console.log("触发了上拉加载" + page);
			
				this.page = page.num;
				this.getData();
			},
			//搜索监听事件
			inputChange(value) {
				this.searchWord = value;
				this.getData();
			},
			
			//点击item
			clickListItem(item) {
				//获取所有页面的栈实例列表
				let pages = getCurrentPages();
				//当前页面
				let nowPage = pages[pages.length - 1];
				//上个页面
				let prevPage = pages[pages.length- 2];
				//传参:第一种方法:通过onShow传参
				// let obj = {
				// 	channelName : item.channelName,
				// 	channelId : item.channelId
				// }
				// prevPage.onShow(obj);
				
				//第二种方法:通过$vm直接赋值
				
				// if(prevPage.$vm.vehicle!=null){
				// 	prevPage.$vm.vehicle.purchaseSupplierId = item.purchaseSupplierId;
				// 	prevPage.$vm.vehicle.purchaseSupplierName = item.supplierName;
				// }
				
				uni.$emit('supplersel', item);
				
				uni.navigateBack()
			}
			
		}
	}
	
</script>

<style>
</style>
